﻿using System.Collections;
using System.Reflection;
using System.Web.Routing;
using Kratos.Framework.Extensions.RouteExtensions;
using Kratos.Framework.Infrastructures;
using Kratos.Modules.Test.Services;
using Kratos.Modules.Test.Services.Impl;
using Microsoft.Practices.Unity;
using System.Web.Mvc;

namespace Kratos.Modules.Test
{
    public class TestModule : IKratosModule, IKratosDataProvider
    {
        private readonly IUnityContainer _container;

        public TestModule(IUnityContainer container)
        {
            _container = container;
        }

        #region IKratosModule 成员

        public void Initialize()
        {

        }

        public void RegisterRoutes(RouteCollection routes)
        {
            string[] nameSpace = new[] { "Kratos.Modules.Test.Controllers" };
            //注册路由信息
            routes.MapLowerCaseRoute(
                "Test",
                "Home/{p}",
                new { controller = "Home", action = "Index", p = 1 },
                new { p = @"\d*" },
                nameSpace
                );
        }

        public void RegisterModelBinders(ModelBinderDictionary modelBinders)
        {
            //注册ModelBinder
            //eg: modelBinders.Add(typeof (ModelBinder), IModelBinder);
        }

        public void RegisterBizServices()
        {
            _container.RegisterType<ITestService, TestService>();
        }

        public void RegisterAction()
        {
            var assembly = Assembly.GetExecutingAssembly();
            SecurityHelper.SetActionByAssembly(assembly);
        }

        public void Unload()
        {

        }

        #endregion

        #region IKratosDataProvider 成员

        public void ConfigDataProvider()
        {
            //注册数据提供程序 Repository
        }

        #endregion
    }
}
